/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/
// 递归
class Solution {
public:
    int maxDepth(Node* root) {
        if(root == nullptr) return 0;
        if(root->children.empty()) return 1;

        int depth = 0;
        for(Node* node : root->children){
            depth = max(maxDepth(node) + 1, depth);
        }

        return depth;
    }
};

// 迭代
class Solution {
public:
    int maxDepth(Node* root) {
        queue<Node*> queue;
        if(root != nullptr) queue.push(root);

        int depth = 0;
        while(queue.empty() == false){
            int num = queue.size();
            depth = depth + 1;
            for(int i = 0; i < num; ++i){
                Node* node = queue.front();
                queue.pop();

                for(Node *tNode : node->children){
                    queue.push(tNode);
                }
            }
        }

        return depth;
    }
};